package o;

import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Context;
import android.os.Handler;
import android.text.TextUtils;
import com.huawei.appgallery.foundation.account.bean.UserSession;
import com.huawei.appgallery.foundation.ui.framework.activity.AbstractBaseActivity;
import com.huawei.appmarket.R;
import BaseDialog.a;

public class dgs implements eqv, eqn, AccountBussinessListener {
    private ProgressDialog ˊ;
    private BaseAlertDialog ˋ;
    private Handler ˎ = new Handler();
    private boolean ˏ = false;
    private boolean ॱ = false;

    public boolean ˎ() {
        return this.ॱ;
    }

    public void ॱ(boolean z) {
        this.ॱ = z;
    }

    public void ॱ() {
        eqq.ˋ().ˎ("UserInfoInspector", this);
        eoj.ˋ().ˎ("UserInfoInspector", this);
    }

    public void ˊ() {
        eqq.ˋ().ˊ("UserInfoInspector");
        eoj.ˋ().ˊ("UserInfoInspector");
        ˏ();
        ˋ();
    }

    public void ˊ(final Activity activity) {
        if (ActivityUtil.isAcitivtyNotValid(activity)) {
            Logger.ˎ("UserInfoInspector", "activity is destroyed.");
            return;
        }
        Logger.ˎ("UserInfoInspector", "isShowing=" + this.ˏ);
        if (!this.ˏ) {
            if (this.ˋ != null) {
                this.ˋ.ˏ();
            }
            this.ˋ = BaseAlertDialog.ˋ(activity, null, activity.getString(R.string.get_userinfo_failed));
            this.ˋ.ॱ();
            this.ˋ.ॱ(a.CONFIRM, (int) R.string.get_userinfo_retry);
            this.ˋ.ॱ(a.CANCEL, (int) R.string.detail_comment_cancel);
            this.ˏ = true;
            this.ˋ.ˎ(false);
            this.ˋ.ˎ(new cks(this) {
                final /* synthetic */ dgs ˎ;

                public void enableNetworking() {
                    this.ˎ.ˏ = false;
                    Logger.ˎ("UserInfoInspector", "GET_USERINFO_FAILED retry get user info");
                    this.ˎ.ॱ(activity);
                    eox.ˎ(activity.getApplicationContext(), false);
                }

                public void upgrade() {
                    this.ˎ.ˏ = false;
                    Logger.ˎ("UserInfoInspector", "GET_USERINFO_FAILED execute logout getUserInfoFailed=" + this.ˎ.ॱ);
                    this.ˎ.ॱ(false);
                    eod.ˏ(activity.getApplicationContext());
                }

                public void ˋ() {
                }
            });
        }
    }

    private void ˏ() {
        if (!ActivityUtil.isAcitivtyNotValid(AbstractBaseActivity.ʻॱ()) && this.ˋ != null) {
            this.ˏ = false;
            this.ˋ.ˏ();
        }
    }

    private void ˋ() {
        if (!ActivityUtil.isAcitivtyNotValid(AbstractBaseActivity.ʻॱ()) && this.ˊ != null && this.ˊ.isShowing()) {
            this.ˊ.dismiss();
        }
    }

    private void ॱ(Context context) {
        if (!ActivityUtil.isAcitivtyNotValid(context)) {
            if (this.ˊ == null) {
                this.ˊ = new ProgressDialog(context);
                this.ˊ.setMessage(context.getString(R.string.str_loading_prompt));
                this.ˊ.setCancelable(false);
                this.ˊ.show();
                ayw.ˊ(this.ˊ.getWindow());
            } else if (!this.ˊ.isShowing()) {
                this.ˊ.show();
                ayw.ˊ(this.ˊ.getWindow());
            }
        }
    }

    public void onResult(final int i) {
        this.ˎ.post(new Runnable(this) {
            final /* synthetic */ dgs ˋ;

            public void run() {
                if (202 == i) {
                    Logger.ˎ("UserInfoInspector", "handler ACCOUNT_GET_USERINFO_SUCCESS");
                    this.ˋ.ॱ(false);
                    this.ˋ.ˏ();
                    this.ˋ.ˋ();
                } else if (203 == i) {
                    Object homeCountry = UserSession.getInstance().getHomeCountry();
                    if (TextUtils.isEmpty(homeCountry)) {
                        String ˏ = eos.ˏ();
                        StringBuilder stringBuilder = new StringBuilder("handler ACCOUNT_GET_USERINFO_FAILED");
                        stringBuilder.append(", cacheHomeCountry=").append(ˏ);
                        stringBuilder.append(", sessionHomeCountry=").append(homeCountry);
                        Logger.ˋ("UserInfoInspector", stringBuilder.toString());
                        if (dof.ˋ(ˏ)) {
                            this.ˋ.ॱ(true);
                            this.ˋ.ˏ();
                            this.ˋ.ˋ();
                            Context ʻॱ = AbstractBaseActivity.ʻॱ();
                            if (!ActivityUtil.isAcitivtyNotValid(ʻॱ)) {
                                this.ˋ.ˊ(ʻॱ);
                                return;
                            }
                            return;
                        }
                        this.ˋ.ॱ(false);
                        if (!ˏ.equals(eqp.ॱ())) {
                            UserSession.getInstance().setHomeCountry(ˏ);
                            eop.ˎ(UserSession.getInstance());
                            eqq.ˋ().ˋ(201);
                            return;
                        }
                        return;
                    }
                    Logger.ˋ("UserInfoInspector", "handler ACCOUNT_GET_USERINFO_FAILED, sessionHomeCountry=null");
                    this.ˋ.ॱ(false);
                }
            }
        });
    }

    public void onAccountBusinessResult(ccp o_ccp) {
        Logger.ˎ("UserInfoInspector", "UserInfoInspector onAccountBusinessResult " + o_ccp);
        if (103 == o_ccp.ˎ) {
            ॱ(false);
            ˏ();
        }
    }
}
